package entities;

import java.util.Comparator;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;


@Entity
@Table(name="FORUMPOSTS"
)
public class Forumposts  implements java.io.Serializable , Comparable<Forumposts>{


     private int id;
     private Date datetime;
     private String author;
     private int tid;
     private String text;
     private double rate;

    public Forumposts() {
    }

    public Forumposts(int id, String author, int tid, String text, double rate) {
       this.id = id;
       this.author = author;
       this.tid = tid;
       this.text = text;
       this.rate = rate;
    }
   
     @Id 
    
    @Column(name="ID", unique=true, nullable=false)
    public int getId() {
        return this.id;
    }
    
    public void setId(int id) {
        this.id = id;
    }
    
    @Column(name="DATETIME", nullable=false, length=50)
    @Temporal(javax.persistence.TemporalType.DATE)
    public Date getDatetime() {
        return this.datetime;
    }
    
    public void setDatetime(Date datetime) {
        this.datetime = datetime;
    }
    
    @Column(name="AUTHOR", nullable=false, length=40)
    public String getAuthor() {
        return this.author;
    }
    
    public void setAuthor(String author) {
        this.author = author;
    }
    
    @Column(name="TID", nullable=false)
    public int getTid() {
        return this.tid;
    }
    
    public void setTid(int tid) {
        this.tid = tid;
    }
    
    @Column(name="TEXT", nullable=false, length=10000)
    public String getText() {
        return this.text;
    }
    
    public void setText(String text) {
        this.text = text;
    }
    
    @Column(name="RATE", nullable=false, precision=52, scale=0)
    public double getRate() {
        return this.rate;
    }
    
    public void setRate(double rate) {
        this.rate = rate;
    }

    

    @Override
    public int compareTo(Forumposts comparable) {
        if(this.getDatetime().before(comparable.getDatetime())){
            return -1;
        } else if(this.getDatetime().after(comparable.getDatetime())){
            return 1;
        } else {
            return 0;
        }
    }


    
}


